package de.gbeine.java.depview.ui.controller;

import com.google.common.eventbus.Subscribe;

import de.gbeine.java.depview.event.ChangeGraphEvent;
import de.gbeine.java.depview.event.ChangeLayoutEvent;
import de.gbeine.java.depview.event.MouseModeEvent;
import de.gbeine.java.depview.event.ShowLabelsEvent;
import de.gbeine.java.depview.model.Element;
import edu.uci.ics.jung.graph.Graph;

/**
 *
 * @author gbeine
 *
 */
public class GraphPanelController {

    /**
     *
     */
    private final GraphPanel graphPanel;
    /**
     *
     */
    private Graph<Element, Number> graph;

    /**
     *
     * @param pGraphPanel
     */
    public GraphPanelController(final GraphPanel pGraphPanel) {
        this.graphPanel = pGraphPanel;
    }

    /**
     *
     * @param pEvent
     */
    @Subscribe
    public void onChangeGraphEvent(final ChangeGraphEvent pEvent) {
        this.graph = pEvent.getGraph();
        this.graphPanel.setGraph(this.graph);
    }

    /**
     *
     * @param pEvent
     */
    @Subscribe
    public void onChangeLayoutEvent(final ChangeLayoutEvent pEvent) {
        this.graphPanel.setGraphLayout(pEvent.getLayout());
    }

    /**
     *
     * @param pEvent
     */
    @Subscribe
    public void onMouseModeEvent(final MouseModeEvent pEvent) {
        this.graphPanel.setMouseMode(pEvent.getMouseMode().mode());
    }

    /**
    *
    * @param pEvent
    */
   @Subscribe
   public void onShowLabelsEvent(final ShowLabelsEvent pEvent) {
       this.graphPanel.showLabels(pEvent.show());
   }
}
